package com.epalmpay.controller.channel.trade;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.order.OrderTradeInDTO;
import com.epalmpay.dto.order.OrderTradeListOutDTO;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.dto.trade.*;
import com.epalmpay.entity.Page;
import com.epalmpay.service.trade.ITradeService;
import com.epalmpay.util.Tools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by wucongpeng on 2017/5/4.
 */
@Controller
@RequestMapping(value = "/channel/device")
public class TradeController extends BaseController {


    @Resource
    private ITradeService tradeService;

    /**
     * 显示钱包交易记录分页列表
     * @param offlineRecordInDTO
     * @param pageDTO
     * @return
     */
    @RequestMapping(value = "/walletRecordList")
    @ResponseBody
    public TradeWalletListOutDTO listWalletRecord(TradeWalletInDTO tradeWalletInDTO, PageDTO pageDTO){
        TradeWalletListOutDTO tradeWalletListOutDTO = new TradeWalletListOutDTO();
        try {
            Page page= Tools.pageEmtity(pageDTO);
            tradeWalletListOutDTO = tradeService.getTradeWalletList(tradeWalletInDTO, page);
            tradeWalletListOutDTO.setPage(page);
            tradeWalletListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return tradeWalletListOutDTO;

        } catch (ApplicationException ae) {
            tradeWalletListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            tradeWalletListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return tradeWalletListOutDTO;
    }

    /**
     * 显示线下交易记录分页列表
     * @param onlineRecordInDTO
     * @param pageDTO
     * @return
     */
    @RequestMapping(value = "/onlineRecordList")
    @ResponseBody
    public TradeListOutDTO listOnlineRecord(TradeInDTO tradeInDTO, PageDTO pageDTO){
        TradeListOutDTO result = new TradeListOutDTO();
        try {
            Page page= Tools.pageEmtity(pageDTO);
            result = tradeService.listOnlineRecords(tradeInDTO, page);
            result.setPage(page);
            result.setErrorCode(Rescode.SUCCESS, "处理成功");
            return result;

        } catch (ApplicationException ae) {
            result.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            result.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 显示线下交易记录分页列表
     * @param onlineRecordInDTO
     * @param pageDTO
     * @return
     */
    @RequestMapping(value = "/onlineOrderRecordList")
    @ResponseBody
    public OrderTradeListOutDTO listOnlineOrderRecord(OrderTradeInDTO orderTradeInDTO, PageDTO pageDTO){
        OrderTradeListOutDTO result = new OrderTradeListOutDTO();
        try {
            Page page= Tools.pageEmtity(pageDTO);
            result = tradeService.listOnlineOrderRecords(orderTradeInDTO, page);
            result.setPage(page);
            result.setErrorCode(Rescode.SUCCESS, "处理成功");
            return result;

        } catch (ApplicationException ae) {
            result.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            result.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return result;
    }

}
